package com.aixin.csopequity.controller;


import com.aixin.csopequity.domain.ConfigEquity;
import com.aixin.csopequity.domain.EquityLevelDef;
import com.aixin.csopequity.model.*;
import com.aixin.csopequity.service.EquityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/equity")
public class EquityController {

    @Autowired
    private EquityService equityService;

    @GetMapping("/equities")
    public Page<ConfigEquity> getEquities(ConfigEquityModel configEquityModel, int pageNum, int pageSize) {
        return equityService.getEquity(configEquityModel, pageNum, pageSize);
    }

    @GetMapping("/equities/{equityID}")
    public ResponseEntity<ConfigEquity> getEquity(@PathVariable String equityID) {
        ConfigEquity equity = equityService.getEquityByID(equityID).orElse(null);
        return ResponseEntity.ok(equity);
    }

    @DeleteMapping("/equities/{equityID}")
    public ResponseEntity<Boolean> deleteEquity(@PathVariable String equityID) {
        equityService.deleteOneEquity(equityID);
        return ResponseEntity.ok(true);
    }

    @PutMapping("/equities")
    public ResponseEntity<Boolean> updateEquity(@RequestBody EquityLevelService model) {
        equityService.saveChangedEquity(model);
        return ResponseEntity.ok(Boolean.TRUE);
    }


//    @RequestMapping("/getEquityByID")
//    public ConfigEquity getEquityByID(String equityID) {
//        return equityService.getEquityByID(equityID);
//    }

    @RequestMapping("/getEquityLevel")
    public List<EquityLevelDef> getEquityLevel(ConfigEquityModel configEquityModel) {
        return equityService.getEquityLevel(configEquityModel.getEquityID());
    }

    @RequestMapping("/saveEquity")
    public SystemReturn saveEquity(@RequestBody EquityLevelService equityLevelService) {
        return equityService.saveEquity(equityLevelService);
    }

    @RequestMapping("/updateEquity")
    public SystemReturn updateEquity(@RequestBody ConfigEquity configEquity) {
        return equityService.updateEquity(configEquity);
    }

    @RequestMapping("/updateEquityLevel")
    public SystemReturn updateEquityLevel(@RequestBody EquityLevelDef equityLevelDef) {
        return equityService.updateEquityLevel(equityLevelDef);
    }

    @RequestMapping("/deleteEquity")
    public SystemReturn deleteEquity(@RequestBody LevelServiceModel levelServiceModel) {
        return equityService.deleteEquity(levelServiceModel.getEquityID());
    }

    @RequestMapping("/deleteEquityLevel")
    public SystemReturn deleteEquityLevel(@RequestBody LevelServiceModel levelServiceModel) {
        return equityService.deleteEquiytLevel(levelServiceModel.getEquityID(), levelServiceModel.getEquityLevelID());
    }

    @RequestMapping("/deleteLevelService")
    public SystemReturn deleteLevelService(@RequestBody LevelServiceModel levelServiceModel) {
        return equityService.deleteLevelService(levelServiceModel.getEquityID(), levelServiceModel.getEquityLevelID(), levelServiceModel.getServiceID());
    }

    @RequestMapping("/saveLevelService")
    public SystemReturn saveLevelService(@RequestBody LevelServiceModel insertLevelService) {
        return equityService.saveLevelService(insertLevelService);
    }

    @RequestMapping("/saveEquityLevel")
    public SystemReturn saveEquityLevel(@RequestBody InsertEquityLevel insertEquityLevel) {
        return equityService.saveEquityLevel(insertEquityLevel);
    }


}
